package thread;

public class BlockTest {
	private String data;
	
	
	/**
	 * @return the data
	 */
	public synchronized String getData() {
		return data;
	}


	/**
	 * @param data the data to set
	 */
	public synchronized void setData(String data) {
		this.data = data;
	}


	class Block implements Runnable {
		boolean flag = false;
		@Override
		public void run() {
			synchronized (Block1.class) {
				try {
					wait();
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				System.out.println("block1 locked in block");
				synchronized (Block.class) {
					System.out.println("block locked in block");
				}
			}
			
		}
		
	}
	
	class Block1 implements Runnable {

		@Override
		public void run() {
			synchronized (Block.class) {
				System.out.println("block locked in block1");
				synchronized (Block1.class) {
					System.out.println("block1 locked in block1");
				}
			}
		}
		
	}
	
	public static void main(String[] args) throws InterruptedException {
		BlockTest b = new BlockTest();
		Block bt1 = b.new Block();
		Block1 bt2 = b.new Block1();
		Thread t1 = new Thread(bt1);
		Thread t2 = new Thread(bt2);
		t1.start();
		t2.start();

		System.out.println("main");
		
	}
}
